function syncTh2EnDate(th_date_id, en_date_id) {
	var th_date = document.getElementById(th_date_id);
	var en_date = document.getElementById(en_date_id);
	var dateTh = th_date.value;        
	var dateThSplit = dateTh.split("/");
	var dateEn = dateThSplit[0]+'/'+dateThSplit[1]+'/'+(parseInt(dateThSplit[2])-543);
	en_date.value = dateEn;		
}
function syncEn2ThDate(en_date_id, th_date_id) {
	var en_date = document.getElementById(en_date_id);
	var th_date = document.getElementById(th_date_id);
	var dateEn = en_date.value;        
	var dateEnSplit = dateEn.split("/");
	var dateTh = dateEnSplit[0]+'/'+dateEnSplit[1]+'/'+(parseInt(dateEnSplit[2])+543);
	th_date.value = dateTh;		
}

// this funnction will synch en-th date value if one of two fields is null
function syncEnThDatePair(en_date_id, th_date_id) {
	var en_date = document.getElementById(en_date_id);
	var th_date = document.getElementById(th_date_id);
	if (!en_date.value && !th_date.value) { return false; }
	if (en_date.value  && th_date.value) { return false; }
	
	if ( en_date.value ) {
		syncEn2ThDate(en_date_id, th_date_id);
	}
	else {
		syncTh2EnDate(th_date_id, en_date_id);
	}
	return true;
}

function updateCalendar(cal, f_date, f_date_th) {
	var f_a = document.getElementById(f_date);
	var f_a_th = document.getElementById(f_date_th);

	var dateFormat = cal.dateFormat;
	var date = cal.date;
	var time = date.getTime();

	var dateEn = date.print(dateFormat);        
	var dateEnSplit = dateEn.split("/");
	var dateTh = dateEnSplit[0]+'/'+dateEnSplit[1]+'/'+(parseInt(dateEnSplit[2])+543);
	// Tek change for display 'en' date when selected
	//f_a_th.value = dateTh;
	f_a_th.value = dateEn;
}

function updateCalendarPair(cal, f_date_a, f_date_a_th, f_date_b, f_date_b_th) {
	var f_a = document.getElementById(f_date_a);
	var f_a_th = document.getElementById(f_date_a_th);
	var f_b = document.getElementById(f_date_b);
	var f_b_th = document.getElementById(f_date_b_th);

	var dateFormat = cal.dateFormat;
	var date = cal.date;
	var time = date.getTime();

	var dateEn = date.print(dateFormat);        
	var dateEnSplit = dateEn.split("/");
	// Tek change for display 'en' date when selected
	//var dateTh = dateEnSplit[0]+'/'+dateEnSplit[1]+'/'+(parseInt(dateEnSplit[2])+543);
    var dateTh = dateEn;   
	// if set f_a propagate change to f_b
	if (f_a == cal.params.inputField) {
		f_a_th.value = dateTh;
		       	
		var aDateEn = f_b_th.value;
		var aDate = Date.parseDate(aDateEn, dateFormat);
		if ( !aDateEn || aDate < date ) {
			f_b.value = dateEn;
			f_b_th.value = dateTh;
		}
	}
	else {
		f_b_th.value = dateTh;
		       	
		var aDateEn = f_a_th.value;
		var aDate = Date.parseDate(aDateEn, dateFormat);
		if ( !aDateEn || aDate > date ) {
			f_a.value = dateEn;
			f_a_th.value = dateTh;
		}
	}
}

function disablePastDate(date) {
	var now = new Date();
	var today = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
	if ( date.getTime() < today.getTime() ) return true;
	return false;
}

function disableWeekend(date) {
	return (date.getDay() == 6 || date.getDay() == 0) ? true : false;
}

if (CalendarUtil == null) var CalendarUtil = {};
CalendarUtil.setCalendarSelector = function(f_date, f_date_th, f_trigger) {
    Calendar.setup({
        inputField     :    f_date,
        button         :    f_trigger,
        //onUpdate       :    function(cal){ updateCalendar(cal, f_date, f_date_th); }
        onUpdate       :    function(cal){ updateCalendar(cal, f_date, f_date_th); if (document.getElementById(f_date_th).onblur) {document.getElementById(f_date_th).onblur();} if (document.getElementById(f_date_th).onchange){document.getElementById(f_date_th).onchange();}} //Modify add call onblur() and onchange() by Mongkol P.
    });
	syncEnThDatePair(f_date, f_date_th);
}

CalendarUtil.setCalanderPairSelector = function(f_date_a, f_date_a_th, f_trigger_a, f_date_b, f_date_b_th, f_trigger_b) {
    Calendar.setup({
        inputField     :    f_date_a,
        button         :    f_trigger_a,
        onUpdate       :    function(cal) { updateCalendarPair(cal, f_date_a, f_date_a_th, f_date_b, f_date_b_th); }
    });
    Calendar.setup({
        inputField     :    f_date_b,
        button         :    f_trigger_b,
        onUpdate       :    function(cal) { updateCalendarPair(cal, f_date_a, f_date_a_th, f_date_b, f_date_b_th); }
    });
	syncEnThDatePair(f_date_a, f_date_a_th);
	syncEnThDatePair(f_date_b, f_date_b_th);

}

<!-- for Messenger Instruction page only !!! -->
CalendarUtil.setCalendarSelector2 = function(f_date, f_date_th, f_trigger) {
    Calendar.setup({
        inputField     :    f_date,
        button         :    f_trigger,
        onUpdate       :    function(cal){ updateCalendar2(cal, f_date, f_date_th); }
    });
	syncEnThDatePair(f_date, f_date_th);
}

function updateCalendar2(cal, f_date, f_date_th) {
	var f_a = document.getElementById(f_date);
	var f_a_th = document.getElementById(f_date_th);

	var dateFormat = cal.dateFormat;
	var date = cal.date;
	var time = date.getTime();

	var dateEn = date.print(dateFormat);        
	var dateEnSplit = dateEn.split("/");
	var dateTh = dateEnSplit[0]+'/'+dateEnSplit[1]+'/'+(parseInt(dateEnSplit[2])+543);
	// Tek change for display 'en' date when selected
	//f_a_th.value = dateTh;
	f_a_th.value = dateEn;
	CalendarUtil.setDayOfWeek(dateEn, 'dayOfWeek');
}
<!-- for Messenger Instruction page only !!! -->

CalendarUtil.setTodayDate = function(date_id)
{
	var en_date = document.getElementById(date_id);
	var now = new Date();
	var today = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
	var dateFormat = "%d/%m/%Y";

	today = today.print(dateFormat);    
	
	en_date.value = today;
}

CalendarUtil.setDayOfWeek = function(text, dayFieldId)
{
	if (!text) return;
	var dayFieldIdObj = document.getElementById(dayFieldId);
	temp = text.split('/');
	if (temp.length < 3) return;
	var myDate = new Date();
	myDate.setFullYear(NumberUtil.parseFloat(temp[2]));
	myDate.setMonth(NumberUtil.parseFloat(temp[1])-1);
	myDate.setDate(NumberUtil.parseFloat(temp[0]));
	dayFieldIdObj.value = Calendar._DN[myDate.getDay()];
}